#include "Camera/Camera.h"
#include "Scene/ISceneManager.h"
#include "Math/Matrix4.h"



namespace tyro
{
	namespace Camera
	{
		Camera::Camera( Scene::ISceneManager* sm )
			:	sceneManager(sm)
			,	rotation(Math::Quaternionf::IDENTITY)
		{
			frustum.Initialise(this);

		}

		void Camera::SetPolygonMode( const PolygonMode& polymode )
		{
			polygonMode = polymode;
		}

		void Camera::SetRotation( const Math::Quaternionf& rot )
		{
			rotation = rot;
		}

		void Camera::SetTranslation( const Math::Vector3f& vec )
		{
			translation = vec;
		}

		const PolygonMode Camera::GetPolygonMode( void ) const
		{
			return polygonMode;
		}

	
		const Math::Quaternionf& Camera::GetRotation() const
		{
			return rotation;
		}

		Scene::ISceneManager* Camera::GetSceneManager( void ) const
		{
			return sceneManager;
		}

		const Math::Vector3f& Camera::GetTranslation() const
		{
			return translation;
		}

		void Camera::RenderScene( Graphics::IViewport* vp )
		{
			sceneManager->RenderScene(this, vp);
		}

		void Camera::SetNearClipDistance( tyro::FLOAT_32 nearDist )
		{
			frustum.SetNearClipDistance(nearDist);
		}

		void Camera::SetAspectRatio( tyro::FLOAT_32 aspectRatio )
		{
			frustum.SetAspectRatio(aspectRatio);
		}

		const Math::Matrix4f& Camera::GetProjectionMatrixRS( void ) const
		{
			return frustum.GetProjectionMatrixRS();
		}

		const Math::Matrix4f& Camera::GetViewMatrix( void ) const
		{
			return frustum.GetViewMatrix();
		}

		void Camera::Rotate( const Math::Vector3f& axis, const Math::Radianf& angle )
		{
			Math::Quaternionf newRotation;
			newRotation.FromAngleAxis(angle, axis);
			Rotate(newRotation);
		}

		void Camera::Rotate( const Math::Quaternionf& newRotation )
		{
			Math::Quaternionf rotationNormal = newRotation;
			rotationNormal.Normalise();
			rotation = rotationNormal * rotation;
			frustum.UpdateView();
		}

		

		

		

		

	}
}